﻿using System;

namespace Borg
{
    public enum ActivationMode
    {
        OnAccess,
        OnComposition,
        OnCreate
    }

    [Serializable]
    public class ExtensionType : Qualifiable
    {
        private Plugin _plugin;

        private MetaElementCollection<PlugType> _plugTypes;
        private MetaElementCollection<SlotType> _slotTypes;

        private ActivationMode _activationMode;

        private bool _isTransparent;
        private string _typeName;

        private string _onActivated;
        private string _onDeactivated;

        private ConstructorType _constructorType;

        internal MetaElementCollection<Extension> extensions;
        internal Extension sharedExtension;

        public Plugin Plugin
        {
            get { return _plugin; }
            internal set { _plugin = value; }
        }

        public MetaElementCollection<PlugType> PlugTypes
        {
            get { return _plugTypes; }
            internal set { _plugTypes = value; }
        }

        public MetaElementCollection<SlotType> SlotTypes
        {
            get { return _slotTypes; }
            internal set { _slotTypes = value; }
        }

        public ActivationMode ActivationMode
        {
            get { return _activationMode; }
            internal set { _activationMode = value; }
        }

        public bool IsTransparent
        {
            get { return _isTransparent; }
            internal set { _isTransparent = value; }
        }

        public string TypeName
        {
            get { return _typeName; }
            internal set { _typeName = value; }
        }

        internal string OnActivated
        {
            get { return _onActivated; }
            set { _onActivated = value; }
        }

        internal string OnDeactivated
        {
            get { return _onDeactivated; }
            set { _onDeactivated = value; }
        }

        internal ConstructorType ConstructorType
        {
            get { return _constructorType; }
            set { _constructorType = value; }
        }

        public override bool IsQualified
        {
            get { return Qualifier.IsQualified(this); }
        }

        public event EventHandler<ExtensionEventArgs> Created
        {
            add { Notifier.AddCreatedHandler(this, value); }
            remove { Notifier.RemoveCreatedHandler(this, value); }
        }

        public event EventHandler<ExtensionEventArgs> Destroyed
        {
            add { Notifier.AddDestroyedHandler(this, value); }
            remove { Notifier.RemoveDestroyedHandler(this, value); }
        }

        internal ExtensionType(int id, string name)
            : base(id, name)
        {
            extensions = new MetaElementCollection<Extension>();
        }

        public override bool Qualify()
        {
            return Qualifier.Qualify(this);
        }

        internal override AssemblyElement GetAssemblyElement()
        {
            return Plugin;
        }
    }
}
